package cn.edu.stu.syllabus.repository.oaRead.local;

import java.util.List;

import cn.edu.stu.syllabus.dao.OaReadEntryDao;
import cn.edu.stu.syllabus.repository.oaRead.OaReadDataSource;
import cn.edu.stu.syllabus.utils.ListUtils;

/**
 * Created by daidaijie on 2017/3/24.
 */

public class OaReadLocalDataSource implements OaReadDataSource {

    OaReadEntryDao mOaReadEntryDao;

    public OaReadLocalDataSource(OaReadEntryDao oaReadEntryDao) {
        mOaReadEntryDao = oaReadEntryDao;
    }

    @Override
    public boolean isRead(long id) {
        List<OaReadEntry> oaReadEntries = mOaReadEntryDao.queryBuilder()
                .where(OaReadEntryDao.Properties.MLocalId.eq(id)).build().list();
        return ListUtils.getListSizeSafety(oaReadEntries) > 0;
    }

    @Override
    public void setRead(long id) {
        OaReadEntry oaReadEntry = new OaReadEntry();
        oaReadEntry.setMLocalId(id);
        mOaReadEntryDao.insertOrReplace(oaReadEntry);
    }

    @Override
    public void clearAllRead() {
        mOaReadEntryDao.deleteAll();
    }
}
